package com.transfiguro.datamodel.csmodels;

import com.transfiguro.datamodel.GenericStatement;
import com.transfiguro.datamodel.Statement;

import java.util.ArrayList;
import java.util.List;

public class CSForStatement extends GenericStatement{
    private String loop;
    private List<Statement> forInit;

    public CSForStatement() {
        REQUIRE_CLOSING = false;
        forInit = new ArrayList<Statement>();
    }

    public boolean isRequireClosing() {
        return REQUIRE_CLOSING;
    }

    public void setLoop(final String loop) {
        this.loop = loop;
    }
    
    public void addForInit(final Statement statement) {
        forInit.add(statement);
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        /**result.append('\t').append(loop).append("{\n");*/
        result.append('\t');
        result.append("for(");
        for(int index = 0; index < forInit.size(); index++) {
            result.append(forInit.get(index).toString().trim());
            if(index<forInit.size() - 1) {
                result.append(';');
            }
        }
        result.append(")");
        result.append("{\n");
        if(statements!=null) {
            for(final Statement statement: statements) {
                result.append(statement.toString()).append(statement.isRequireClosing()? ';' : "");
            }
        }
        result.append("\n}");
        return result.toString();
    }

    public List<Statement> getForInit() {
        return forInit;
    }

    public void setForInit(final List<Statement> forInit) {
        this.forInit = forInit;
    }
}
